//
//  LBCouponController.m
//  loveBeen
//
//  Created by 郭小双 on 16/11/22.
//  Copyright © 2016年 loveBeen. All rights reserved.
//

#import "LBCouponController.h"
#import "LBCouponModel.h"
#import "LBDiscountCell.h"
static NSString *cellID = @"cellID";
@interface LBCouponController ()<UITableViewDataSource>
@property(nonatomic,weak)UITableView *tableView;

@end

@implementation LBCouponController{
    NSArray<LBCouponModel *>*_dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    [self setupUI];
    
}


- (void)loadData{
    NSURL *url = [[NSBundle mainBundle]URLForResource:@"LBCoupon.plist" withExtension:nil];
    NSArray *array = [NSArray arrayWithContentsOfURL:url];
    _dataArray = [NSArray yy_modelArrayWithClass:[LBCouponModel class] json:array];
    
    
    
}

- (void)setupUI{
    
    //创建一个rightBarButtonItem按钮
    UIBarButtonItem *bItem = [[UIBarButtonItem alloc] initWithTitle:@"使用规则" style:UIBarButtonItemStylePlain target:nil action:nil];
     self.navigationItem.rightBarButtonItem = bItem;
    
    //设置导航title
    self.navigationItem.title = @"优惠券";
   
    //self.navigationItem.rightBarButtonItem.
 //   self.rightBarButtonItem.title = @"使用规则";
    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];

    tableView.dataSource = self;
    [self.view addSubview:tableView];
    self.tableView = tableView;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"LBDiscountCell" bundle:nil] forCellReuseIdentifier:@"cellID"];
  
    tableView.estimatedRowHeight = 160;
    tableView.rowHeight = UITableViewAutomaticDimension;
    
    UIView *headView = [[[UINib nibWithNibName:@"LBDiscountHeadView" bundle:nil]instantiateWithOwner:self options:0]lastObject];
    tableView.tableHeaderView = headView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LBDiscountCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];
    cell.model = _dataArray[indexPath.row];
    
    return cell;
    
    
    
}

-(void)viewWillAppear:(BOOL)animated {
    //屏蔽统一navigationBar的样式，自定义样式
    [self.navigationController.navigationBar setTintColor:[UIColor grayColor]];
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
